<template>
    <div id="health">
        <div class="contains">
            <div style="margin: 8% 12% 0% 12%;">
                <nut-input v-model="inf.temperature" left-icon="dongdong" type="number" clearable placeholder="请输入体温" />
                <nut-input v-model="inf.virustest" left-icon="dongdong" clearable placeholder="核酸监测信息" />
                <nut-input v-model="inf.trip" left-icon="dongdong" clearable placeholder="行程信息" />
            </div>
            <div style="padding: 5%">
                <nut-button type="default" @click="commit">提交申报</nut-button>
            </div>
        </div>
    </div>
</template>

<script>
import { ref } from "vue";
import common from '../Common.vue'
import axios from "axios";
import { Toast } from '@nutui/nutui';

export default {
    components: {},
    setup() {
        // 从后端获取用户信息
        const inf = ref({
            id: common.getLoginState().id,
            temperature: "",
            virustest: "",
            trip: "",
            status: 0
        });
        
        return {
            inf
        };
    },
    mounted() {
    },
    methods: {
        commit: function() {
            if (this.inf.id == -1) {
                Toast.fail("登录信息失效，请重新登录！");
                return;
            } else if (this.inf.temperature == "" || this.inf.virustest == "" || this.inf.trip == "") {
                Toast.fail("以上三项都不能为空！");
                return;
            }
            if (this.inf.virustest.indexOf("死亡") !== -1) {//去世，紫码
                this.inf.status = 3;
            } else if (this.inf.virustest.indexOf("阳性") !== -1) { // 如果阳性了 设为红码
                this.inf.status = 2;
            } else if (this.inf.temperature > 37.3) { // 如果发烧了 设为黄码
                this.inf.status = 1;
            }
            
            
            axios
                .post(common.apiUrl + "/api/healthCommit", this.inf)
                .then((res) => { 
                    if (res.data.state) {
                        Toast.text(res.data.msg);
                        this.$router.back();
                    } else {
                        Toast.fail(res.data.msg);
                    }
                });
        }
    }
};
</script>

<style>
    body {
        background-color: rgb(165, 126, 255);
    }
    #health {
        width: 100%;
        height: 100vh;
        display: flex;
        justify-content: center;
        align-items: center;
        /* background-color: #fff; */
    }
    .contains {
        width: 80%;
        padding: 0px 2rem 0px 2rem;
        background-color: #ffffff;
        border-radius: 8px;
        -moz-border-radius: 8px;
        -webkit-border-radius: 8px;
        box-shadow: 0px 1px 5px rgba(48, 48, 48, 0.5);
    }
</style>